<!-- 头部插件 -->
<template>
  <div class="header-nav" :class="{'headerNavBGC': isShowNavBGC}">
    <el-row type="flex" justify="center">
      <el-row class="middle-content" type="flex" align="middle">
        <el-col :span="12">您好，欢迎来到宜春联合信用资产交易所</el-col>
        <el-col :span="12">
          <!-- 未登录 -->
          <el-row type="flex" justify="end" align="middle" v-if="!isLogin">
            <div class="service-telephone">客服电话：400-0000-000</div>
            <div class="login btn" @click="herfto('login')">登录</div>
            <div class="register btn" @click="herfto('register')">注册</div>
          </el-row>
          <!-- 登录 -->
          <el-row type="flex" justify="end" align="middle" v-if="isLogin">
            <div class="service-telephone">客服电话：400-0000-000</div>
            <div class="handle-region">
              <NewsNotify class="news-notify" />
              <div class="profiles" @click="herfto('profiles')">【{{userName}}】</div>
              <div class="register btn" @click="ulogout">退出</div>
            </div>
          </el-row>
        </el-col>
      </el-row>
    </el-row>

    <el-row type="flex" justify="center">
      <el-row class="middle-content" type="flex" align="middle">
        <el-col :span="6" class="title">
          <el-row type="flex" justify="start">
            <img src="../../assets/logo.png" style="width:184px;height:42px" alt />
          </el-row>
        </el-col>
        <el-col :span="18">
          <el-row type="flex" justify="end" v-show="!isShow" @click.native="herfto('index')">返回网站首页</el-row>
          <el-row type="flex" justify="end" v-show="isShow">
            <el-col
              class="menu"
              v-for="(item,index) in navList1"
              :key="index"
              @click.native="navChange(item,index)"
            >
              {{item}}
              <div class="line" v-show="index==currIndex"></div>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-row>
  </div>
</template>


<script>
import {logout} from '@/api/user'

import store from '@/store'
import NewsNotify from './NewsNotify'

let navList1 = ['网站首页', '资产交易', '信息披露', '会员服务', '政策服务', '关于我们']
let navList2 = ['index', 'propsTrade', 'info', 'vip', 'law', 'about']

let navShowName = ['index', 'vip', 'about', 'law', 'info', 'propsTrade']
let navBGCName = ['index', 'login', 'vip', 'about', 'law', 'info', 'propsTrade']
let propsTradeChildPath = ['/propsTrade/tradeinfo', '/propsTrade/tradeenroll']

export default {
  components: {
    NewsNotify
  },
  props: {},
  data() {
    return {
      navList1,
      navList2,
      currIndex: 0
    }
  },
  computed: {
    userName() {
      return this.$store.state.user.userInfo.name
    },
    isLogin() {
      return !!(this.$store.state.user.token)
    },
    isShowNavBGC() {
      if (navBGCName.includes(this.$route.name) && !propsTradeChildPath.includes(this.$route.path)) {
        return false
      } else {
        return true
      }
    },
    isShow() {
      if (navShowName.includes(this.$route.name)) {
        // this.activeIndex = 'index'
        return true
      } else {
        return false
      }
    }
  },
  methods: {
    navChange(item, index) {
      this.currIndex = index
      let pathName = this.navList2[index]
      this.herfto(pathName)
    },
    ulogout() {
      this.$confirm('是否退出系统, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          this.$router.push({path: '/login'})
        })
      })
    },
    herfto(name) {
      this.$router.push({path: `/${name}`})
      this.currIndex = this.navList2.indexOf(name)
    }
  },
  watch: {
    '$route.name': function (newVal, oldVal) {
      let pathName = this.$route.name
      this.currIndex = this.navList2.indexOf(pathName)
    }
  },
  created() {},
  mounted() {
    let pathName = this.$route.name
    this.currIndex = this.navList2.indexOf(pathName)
  }
}
</script>


<style lang='less' scoped>
.menu {
  position: relative;
  width: 120px;
  line-height: 24px;
  text-align: center;
  cursor: Pointer;
  .line {
    width: 34px;
    height: 3px;
    background: #ffffff;
    position: absolute;
    top: 30px;
    left: 42px;
  }
}

.news-notify {
  position: relative;
  z-index: 9999;
}

.headerNavBGC {
  background-color: #072163;
}
.header-nav {
  font-size: 14px;
  line-height: 14px;
  color: #ffffff;

  > .el-row:first-child {
    padding: 8px 0;
    background-color: rgba(0, 0, 0, 0.07);
    .service-telephone {
      text-align: right;
      padding-right: 32px;
    }
    .register {
      margin-left: 12px;
      background-color: rgba(255, 255, 255, 0.4);
    }
    .notify {
      .el-icon-message-solid {
        font-size: 18px;
      }
      /deep/ .el-badge__content.is-dot {
        width: 6px;
        height: 6px;
      }
    }
    .profiles {
      margin-left: 12px;
    }
    .handle-region {
      display: flex;
      align-items: center;
    }
  }
  > .el-row:last-child {
    font-size: 16px;
    padding: 20px 0;
    .title {
      font-size: 24px;
      line-height: 24px;
    }
    .el-menu {
      background-color: unset;
      .el-menu-item {
        font-size: 16px;
      }
      .el-menu-item:hover,
      .el-menu-item:focus {
        background-color: unset;
      }
    }
    .el-menu.el-menu--horizontal {
      border: unset;
    }
  }
}
.btn {
  display: inline-block;
  border: 1px solid #fff;
  border-radius: 100px;
  padding: 4px 12px;
}
</style>
